<!-- 顾客登录后 还车页面prereturncar.php -->

<!DOCTYPE html>
<html>
<?php
session_start();
require 'connection.php';
$conn = Connect();
?>

<head>
    <link rel="shortcut icon" type="image/png" href="assets/img/P.png.png">

    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/customerlogin.css">
    <script type="text/javascript" src="assets/js/jquery.min.js"></script>
    <script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="assets/css/clientpage.css" />
</head>

<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
    <!-- 导航栏 -->
    <?php
    include './nav.php';
    ?>

    <?php
    // 获取登录顾客的用户名
    $login_customer = $_SESSION['login_customer'];

    // 查询需要归还的车辆信息
    $sql1 = "SELECT c.car_name, rc.rent_start_date, rc.rent_end_date, rc.fare, rc.charge_type, rc.id 
         FROM rentedcars rc, cars c
         WHERE rc.customer_username='$login_customer' AND c.car_id=rc.car_id AND rc.return_status='NR'";
    $result1 = $conn->query($sql1);

    // 如果有需要归还的车辆
    if (mysqli_num_rows($result1) > 0) {
    ?>
        <div class="container">
            <div class="jumbotron">
                <h1 class="text-center">在这里归还您的车辆</h1>
                <p class="text-center">希望您喜欢我们的服务</p>
            </div>
        </div>

        <div class="table-responsive" style="padding-left: 100px; padding-right: 100px;">
            <table class="table table-striped">
                <thead class="thead-dark">
                    <tr>
                        <th width="30%">车辆</th>
                        <th width="20%">租车开始日期</th>
                        <th width="20%">租车结束日期</th>
                        <th width="20%">租金</th>
                        <th width="10%">操作</th>
                    </tr>
                </thead>
                <?php
                // 循环输出需要归还的车辆信息
                while ($row = mysqli_fetch_assoc($result1)) {
                ?>
                    <tr>
                        <td><?php echo $row["car_name"]; ?></td>
                        <td><?php echo $row["rent_start_date"] ?></td>
                        <td><?php echo $row["rent_end_date"]; ?></td>
                        <td>¥ <?php
                                // 根据计费类型输出租金信息
                                if ($row["charge_type"] == "days") {
                                    echo ($row["fare"] . "/天");
                                } else {
                                    echo ($row["fare"] . "/公里");
                                }
                                ?></td>
                        <td><a href="returncar.php?id=<?php echo $row["id"]; ?>"> 还车 </a></td>
                    </tr>
                <?php } ?>
            </table>
        </div>
    <?php } else {
        // 如果没有需要归还的车辆
    ?>
        <div class="container">
            <div class="jumbotron">
                <h1 class="text-center">没有需要归还的车辆。</h1>
                <p class="text-center">希望您喜欢我们的服务</p>
            </div>
        </div>
    <?php
    } ?>
</body>

<footer class="site-footer">
    <div class="container">
        <hr>
        <div class="row">
            <div class="col-sm-6">
                <h5>© <?php echo date("Y"); ?> 租车服务</h5>
            </div>
        </div>
    </div>
</footer>

</html>